package org.yan.stock.server.core;

import java.io.IOException;
import java.util.logging.Logger;

import org.yan.stock.server.c2dm.C2DMessaging;
import org.yan.stock.server.client.Client;
import org.yan.stock.server.client.Stock;
import org.yan.stock.server.util.StrUtil;

public abstract class MessageNotifier {
	private static final Logger log = Logger.getLogger(C2DMessaging.class.getName());
	
	public static void notify(Client client) {
		Messaging messaging = null;
		String os = client.getOs();
		if("Android".equals(os)) {
			messaging = C2DMessaging.get();
		}
		else if("iOS".equals(os)) {
			
		}
		Stock[] stocks = client.getStockArr();
		String msg = StrUtil.arr2String(stocks, "board", "|");
		try {
			messaging.sendNoRetry(client.getAuthId(), null, "Msg",msg);
		} catch (IOException e) {
			log.warning("Sending to client:" + client.getAuthId() + " failed.");
		}
	}

}
